//
//  WNY_Top_TableViewCell.m
//  TheRoadAD
//
//  Created by ym on 16/8/24.
//  Copyright © 2016年 baixue. All rights reserved.
//

#import "WNY_Top_TableViewCell.h"
#import "contentMessangeView.h"
#import "UserLikeView.h"

@interface WNY_Top_TableViewCell ()
{
    contentMessangeView *messangeView;
    UserLikeView *friendView;
    
}

@end

@implementation WNY_Top_TableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.scroView.showsVerticalScrollIndicator = NO;
    self.scroView.showsHorizontalScrollIndicator = NO;
    self.scroView.pagingEnabled = YES;
    messangeView = [[[NSBundle mainBundle] loadNibNamed:@"contentMessangeView" owner:nil options:nil] lastObject];
    [self.contentView addSubview:messangeView];
    friendView  = [[UserLikeView alloc] init];
    [self.contentView addSubview:friendView];
    self.userImageBtn.sd_layout.topSpaceToView(self.contentView,10).leftSpaceToView(self.contentView,15).widthIs(40).heightIs(40);
    self.userImageBtn.layer.masksToBounds = YES;
    self.userImageBtn.layer.cornerRadius = 20;
    self.userName.sd_layout.topSpaceToView(self.contentView,12).leftSpaceToView(self.userImageBtn,10).heightIs(20).rightSpaceToView(self.contentView, 15);
    self.userTime.sd_layout.leftEqualToView(self.userName).topSpaceToView(self.userName,5).heightIs(15);
    
    [self.userImageBtn addTarget:self action:@selector(jumpToOtherHomePage) forControlEvents:UIControlEventTouchUpInside];

}
- (void)setModel:(WNY_TOP_Model *)model{
    _model = model;
    NSInteger a = model.imagePathsArray.count;
    friendView.imageArr = model.imageLike;
    
    if (a == 0) {
        self.scroView.hidden = YES;
        self.teomLl.hidden = YES;
        self.Tiltle.sd_layout.topSpaceToView(self.userImageBtn,5).leftSpaceToView(self.contentView,21).rightEqualToView(self.contentView).autoHeightRatio(0);
        self.consent.sd_layout.leftSpaceToView(self.contentView,21).rightSpaceToView(self.contentView,21).topSpaceToView(self.Tiltle,10).autoHeightRatio(0);
        messangeView.sd_layout.topSpaceToView(self.consent,15).leftEqualToView(self.Tiltle).rightEqualToView(self.contentView).heightIs(120);
    

    }else{
        self.scroView.sd_layout.leftEqualToView(self.contentView).rightEqualToView(self.contentView).heightIs(180).topSpaceToView(self.contentView,60);
        
        self.Tiltle.sd_layout.topSpaceToView(self.scroView,9).leftSpaceToView(self.contentView,21).rightEqualToView(self.contentView);
        self.consent.sd_layout.leftSpaceToView(self.contentView,21).rightSpaceToView(self.contentView,21).topSpaceToView(self.Tiltle,10).autoHeightRatio(0);
        messangeView.sd_layout.topSpaceToView(self.consent,15).leftEqualToView(self.Tiltle).rightEqualToView(self.contentView).heightIs(120);
        
    
    }   
    self.teomLl.sd_layout.rightSpaceToView(self.contentView,15).bottomSpaceToView(self.Tiltle,15).autoHeightRatio(0);
        friendView.sd_layout.topSpaceToView(messangeView,15).leftEqualToView(messangeView).rightEqualToView(self.contentView).heightIs(30);
    self.teomLl.text = [NSString stringWithFormat:@"%ld图", model.imagePathsArray.count];
    [self.userImageBtn setBackgroundImage:[UIImage imageNamed:model.iconImagePath] forState:0];
    self.userName.text = model.userName;
    self.userTime.text = model.time;
    self.Tiltle.text = model.title;
    
 
    self.consent.text = model.conxxxx;
    
    for (NSInteger i = 0 ; i <  model.imagePathsArray.count; i++) {
        UIImageView *image = [[UIImageView alloc] init];
        image.frame = CGRectMake(Screen_Width * i, 0, Screen_Width, 180);
        [self.scroView addSubview:image];
        NSString *str = model.imagePathsArray[i];
        image.image = [UIImage imageNamed:str];
    }
    self.scroView.contentSize = CGSizeMake(Screen_Width *  model.imagePathsArray.count, 0);
    messangeView.day.text =  model.numberOfDay;
    messangeView.time.text = model.overTime;
    messangeView.location.text = model.location;
    messangeView.people.text = model.numberOfPeople;
    messangeView.drive.text = model.Drive;
    
      [self setupAutoHeightWithBottomView:friendView bottomMargin:10];
}


- (void)jumpToOtherHomePage{
    _othersHomePage();
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
